class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int n = nums.length;
        int left = 0;
        int right = 0;
        int sum = 0;
        int ret = n;
        boolean flag = false;
        while(right < n) {
            sum += nums[right];
            while(sum >= target) {
                flag = true;
                ret = ret < right - left + 1 ? ret : right - left + 1;
                sum -= nums[left];
                left++;
            }
            right++;
        }
        if(flag == false) {
            return 0;
        }
        return ret;
    }
}